import 'package:flutter/material.dart';
import 'package:flutter_vant/component/cell.dart';
import 'package:rlstyles/main.dart';

class VanCellGroup extends HookWidget {
  final dynamic icon;
  final List<VanCell> children;
  // 分组标题
  final String? title;
  // 卡片分格
  final bool? inset;
  const VanCellGroup(
      {this.children = const [], this.icon, this.inset = false, this.title});
  getStyles() {
    return {
      'main': {
        CssRule.flexDirection: 'col',
        CssRule.width: double.infinity,
      },
      'inset': {
        CssRule.backgroundColor: 'white',
        CssRule.borderRadius: 10,
        CssRule.marginLeft: 10,
        CssRule.marginRight: 10
      }
    };
  }

  renderCell() {
    return children.length > 0 ? children : [Container()];
  }

  renderTitle() {
    if (title == null) return SizedBox();
    return Frame(
      styles: {
        CssRule.color: 'rgb(150, 151, 153)',
        CssRule.marginBottom: 10,
        CssRule.fontSize: 14
      },
      children: [TextView(title!)],
    );
  }

  @override
  Widget build(BuildContext context) {
    Map css = {
      'main': true,
      'inset': this.inset,
    };
    final style = StylesMap.getClass(css, getStyles());
    return Frame(styles: style, children: [
      renderTitle(),
      ...renderCell(),
    ]);
  }
}
